package com.maya.controller;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.maya.model.Question;
import com.maya.model.User;
import com.maya.service.QuestionService;




@Controller
public class ViewFollowingQuestionsController  {
	
	
	@Autowired
	private QuestionService questionService;
	
	@RequestMapping("/followingquestions")
    public String  viewFollowingQuestions(HttpSession session,Model model){
        
		User user = (User)session.getAttribute("currUser");
        if(null == user) {
            
            return "redirect:/viewallquestions";
        }
        
        List<ObjectId> qids = user.getFollowedQuestionIds();
        if(qids.size() <= 0) {
            
            return "questions";
        }
        
        List<Question> questions = questionService.find(qids);
        
        model.addAttribute("questions", questions);
        model.addAttribute("title", "我关注的问题");
        
        return "questions";
        
        
        
    }
    
    
    
    
}
